<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>DebridMax Chrome Extension: Popup</title>
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="const.js"></script>
	<script type="text/javascript">
	//<![CDATA[
	var myWindow;
	//Get backgroundpage
	bg = chrome.extension.getBackgroundPage();

	function openSubWindow() {
		bg.openNewWindow("submissionWindow.html");
	}
	
	//Open login page in new tab
	function openLoginForm(host) {
		chrome.tabs.create({url:host});
	}

	//Set login, credit, and server load html;
	function setDetails() {
		$("#dm_details").html(bg.login_details.DM.user);
		
		/* Server stats */
		/*
		$("#premium_account_stats").load("http://www.debridmax.com div#useful-links table",function(){ 
			//replace dt.host_p css's background-url with DM_ROOT instead of the extension's URL
			$("dt.host_p").each(function(){
				$(this).css("background",$(this).css("background").replace("chrome-extension://opoiifdgfgecnammngihaedbgcajohbl/",DM_ROOT));
			});
		});
		*/
	}

	$(document).ready(function(){
	   
		//Initiate refresh button for login/server details
		var notloggedin_text = chrome.i18n.getMessage("background_notloggedin") + '(<a href=javascript:openLoginForm("' + chrome.i18n.getMessage("background_debridmax_url") + "login.php" + '")>'+chrome.i18n.getMessage("background_login_link")+'</a>).';
		
		//if auto-login is set, no need to call init when open the popup window
		if(bg.login_details.DM.user == "" || localStorage["auto-login"] == 0 || localStorage["auto-login"] == "" || 
			localStorage["auto-login-pass"]=="" || localStorage["auto-login-user"]=="")
			bg.init();
					
		if(bg.login_details.DM.user == notloggedin_text || bg.login_details.DM.user =="")
			$("#subWindow").hide();
		else
			$("#subWindow").show();
		
		//Write login, credit, and server load;
		setDetails();
		
		//Add root server url prior to the img src 
		$("img").each(function(){
			$(this).attr({src:DM_ROOT + $(this).attr('src')});
		});
		
		$("#subWindow").text(chrome.i18n.getMessage("popup_downloader_text"));
		
	});
	//]]>
	</script>

	<style type="text/css">
	body {
		background: #000;
		margin: 0;
		padding: 0;
		font: 12px normal Verdana, Arial, Helvetica, sans-serif;
		color: #fff;
		min-width:100px;
		overflow-x:hidden;
	}

	.container {width: 200px; margin: 10px auto;}
	
	a {
	color : #ff0000;
	}
	a:hover {
	text-decoration : none;
	}
	</style>
</head>

<body>
	<div class="container">
		<div id="logindetails" style="display:inline;">
			<div id="dm_details"></div>
			<a href="javascript:openSubWindow();" id="subWindow"></a>
		</div>
	</div>
</body>
</html>